<?
$arParams['MAX_MESSAGES_IN_CHAT'] = (int) $arParams['MAX_MESSAGES_IN_CHAT'];
if(!$arParams['MAX_MESSAGES_IN_CHAT']) $arParams['MAX_MESSAGES_IN_CHAT'] = 50;

$arResult = array();

$arResult['ACTION'] = strtoupper($_REQUEST[$arParams['ACTION_VARIABLE']]);

if($arResult['ACTION'] == 'REFRESH_CHAT')
{
	$arResult['MESSAGES'] = CChat::GetListMessages(array(
		'ID' => $_REQUEST['LAST_UPDATE_ID']
	));
}
elseif($arResult['ACTION'] == 'ADD_MESSAGE')
{
	$id = CChat::AddMessage(array(
		'CREATED_BY'   => $_REQUEST['userid'],
		'USER_NAME'    => 'admin',
		'MESSAGE'      => htmlspecialchars(preg_replace('/([^\s]{25})[^\s]+/', '$1...', $_REQUEST['MESSAGE'])),
		'TYPE_MESSAGE' => 'MESSAGE'
	));
}

if(!$this->InitCache(10, "cache_id"))
{
	// Include template
	$this->IncludeTemplate();
}
else
{
	echo 'Взято из кеша';
}